package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.coupon.Coupon;
import com.breakfast.fun.util.L;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/8.
 */

public class GiftAdapter extends BaseListAdapter<Coupon.CouponData> {

    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public GiftAdapter(Context context, List<Coupon.CouponData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gift, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        if(position == 0){
//            holder.mLlItemGiftUp.setVisibility(View.VISIBLE);
//        }else{
//            holder.mLlItemGiftDown.setVisibility(View.GONE);
//        }
//        if(position == mList.size() - 1){
//            holder.mLlItemGiftDown.setVisibility(View.VISIBLE);
//        }else{
//            holder.mLlItemGiftUp.setVisibility(View.GONE);
//        }

//        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.mLlUserItemGift.getLayoutParams();
//        params.height = 160;
//        holder.mLlUserItemGift.setLayoutParams(params);

        Coupon.CouponData couponData = mList.get(position);
        holder.mTvUserGiftCondition.setText("· 满" + couponData.getConditions() + "元可用");

        Date date = new Date();
        try {
            date = mSimpleDateFormat.parse(couponData.getCreateTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//        calendar.add(Calendar.DATE,couponData.getDeadTime());
//        holder.mTvUserGiftBettwenTime.setText("· 有效期至" + mSimpleDateFormat.format(calendar.getTime()));

        holder.mTvUserGiftBettwenTime.setText("· 有效期" + couponData.getDeadTime() + "天");
        holder.mTvUserItemGiftPrice.setText(couponData.getValue() + "");
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_user_gift_condition)
        TextView mTvUserGiftCondition;
        @Bind(R.id.tv_user_gift_bettwenTime)
        TextView mTvUserGiftBettwenTime;
        @Bind(R.id.ll_user_item_gift)
        LinearLayout mLlUserItemGift;
        @Bind(R.id.tv_user_item_gift_price)
        TextView mTvUserItemGiftPrice;
        @Bind(R.id.ll_item_gift_up)
        LinearLayout mLlItemGiftUp;
        @Bind(R.id.ll_item_gift_down)
        LinearLayout mLlItemGiftDown;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
